Predavani obrazku (TBitmap) pres COM/DCOM

Otázka od: Libor Filip

12. 11. 2002 6:37

Zdarvim konferenci.
Pokousim se z COM serveru poslat na klienta obrazek.
Zkousim to pres TOleVariant (podle prikladu v konferenci),
ale stale se mi nedari.
Muze mi nekdo kouknout na kod a rici, kde delam chybu?

COM server

function TCOMServer.Get_Logo: OleVariant;
var
  TempStream:TMemoryStream;
  P:Pointer; L:Integer; V:OleVariant;
begin
  TempStream:=TMemoryStream.Create;
  try
    Logo.SaveToStream(TempStream); //Logo: TBitmap
    L:=TempStream.Size;
    V:=VarArrayCreate([0,L-1], varByte);
    P:=VarArrayLock(V);
    TempStream.ReadBuffer(Buffer^,L);}
    try
      Move(TempStream.Memory^,P^,L);
    finally
      VarArrayUnLock(V);
    end;
    Result:=V;
  finally
    TempStream.Free;
  end;
end;

COM klient

procedure TKonfUctJed.SetImage(Value: OleVariant);
var
  P: Pointer;
  L: integer;
  TempStream:TMemoryStream;
begin
  L:=VarArrayHighBound(Value,1)-VarArrayLowBound(Value,1)+1;
  P:=VarArrayLock(Value);
  try
    TempStream:=TMemoryStream.Create;
    try
      TempStream.WriteBuffer(P^,L);
      Image1.Picture.Bitmap.LoadFromStream(TempStream); //obrazek chci
zobrazit v TImage
    finally
      TempStream.Free;
    end;
  finally
    VarArrayUnLock(Value);
  end;
end;


Predem dekuji za radu
  Libor Filip


Odpovedá: Richard Kejval

12. 11. 2002 9:24

 
Ahoj,
 melo by to byt asi takhle, ale pisu to z hlavy, tak tam muze
 byt chyba, asi by to slo i bez toho tempstreamu, ale nechal
 jsem ho tam.

server:
function TCOMServer.Get_Logo: OleVariant;
 var
   TempStream:TMemoryStream;
   P:Pointer; L:Integer;
   Buffer:PChar;
 begin
  TempStream:=TMemoryStream.Create;
  try
    Logo.SaveToStream(TempStream); file://Logo: TBitmap
    L:=TempStream.Size;
    GetMem(Buffer,L);
    TempStream.ReadBuffer(Buffer^,L);
  finally
    TempStream.Free;
  end;
  Result:=VarArrayCreate([0,L-1],varByte);
  P:=VarArrayLock(Result);
  try
    Move(Buffer^,P^,L);
  finally
    VarArrayUnLock(Result);
  end;
  FreeMem(Buffer,L);
 end;


klient :
procedure TKonfUctJed.SetImage;
var
  P: Pointer;
  L: integer;
  TempStream:TMemoryStream;
  V:OleVariant;
begin
    V:=ComServer.Logo;
    L:=VarArrayHighBound(V,1)-VarArrayLowBound(V,1)+1;
    GetMem(Buffer,L);
    P:=VarArrayLock(V);
    try
      Move(P^,Buffer^,L);
    finally
      VarArrayUnLock(V);
    end;

    TempStream:=TMemoryStream.Create;
    try
      TempStream.WriteBuffer(Buffer^,L);
      Image1.Picture.Bitmap.LoadFromStream(TempStream);file://obrazek
    finally
      TempStream.Free;
    end;
    FreeMem(Buffer,L);
 end;


S pozdravem
ing. Richard Kejval
IC Software s.r.o
Mobil: +420602477679

Odpovedá: Richard Kejval

12. 11. 2002 9:22

 
Ahoj,
 melo by to byt asi takhle, ale pisu to z hlavy, tak tam muze
 byt chyba, asi by to slo i bez toho tempstreamu, ale nechal
 jsem ho tam.

server:
function TCOMServer.Get_Logo: OleVariant;
 var
   TempStream:TMemoryStream;
   P:Pointer; L:Integer;
   Buffer:PChar;
 begin
  TempStream:=TMemoryStream.Create;
  try
    Logo.SaveToStream(TempStream); file://Logo: TBitmap
    L:=TempStream.Size;
    GetMem(Buffer,L);
    TempStream.ReadBuffer(Buffer^,L);
  finally
    TempStream.Free;
  end;
  Result:=VarArrayCreate([0,L-1],varByte);
  P:=VarArrayLock(Result);
  try
    Move(Buffer^,P^,L);
  finally
    VarArrayUnLock(Result);
  end;
  FreeMem(Buffer,L);
 end;


klient :
procedure TKonfUctJed.SetImage;
var
  P: Pointer;
  L: integer;
  TempStream:TMemoryStream;
  V:OleVariant;
begin
    V:=ComServer.Logo;
    L:=VarArrayHighBound(V,1)-VarArrayLowBound(V,1)+1;
    GetMem(Buffer,L);
    P:=VarArrayLock(V);
    try
      Move(P^,Buffer^,L);
    finally
      VarArrayUnLock(V);
    end;

    TempStream:=TMemoryStream.Create;
    try
      TempStream.WriteBuffer(Buffer^,L);
      Image1.Picture.Bitmap.LoadFromStream(TempStream);file://obrazek
    finally
      TempStream.Free;
    end;
    FreeMem(Buffer,L);
 end;


S pozdravem
ing. Richard Kejval
IC Software s.r.o
Mobil: +420602477679

Odpovedá: Libor Filip

12. 11. 2002 11:20

Ahoj,
  bohuzel to takhle nechodi. Padne to na radku

TempStream.ReadBuffer(Buffer^,L); //Zde se vyhlasi chyba cteni proudu.

  Jestli te jeste neco napada, tak budu vdecny za kazdou radu.

Libor

-----Original Message-----
From: delphi-l-owner@clexpert.cz [mailto:delphi-l-owner@clexpert.cz]On
Behalf Of Richard Kejval
Sent: Tuesday, November 12, 2002 9:04 AM
To: delphi-l@clexpert.cz
Subject: Re: Predavani obrazku (TBitmap) pres COM/DCOM


 
Ahoj,
 melo by to byt asi takhle, ale pisu to z hlavy, tak tam muze
 byt chyba, asi by to slo i bez toho tempstreamu, ale nechal
 jsem ho tam.

server:
function TCOMServer.Get_Logo: OleVariant;
 var
   TempStream:TMemoryStream;
   P:Pointer; L:Integer;
   Buffer:PChar;
 begin
  TempStream:=TMemoryStream.Create;
  try
    Logo.SaveToStream(TempStream); file://Logo: TBitmap
    L:=TempStream.Size;
    GetMem(Buffer,L);
    TempStream.ReadBuffer(Buffer^,L);
  finally
    TempStream.Free;
  end;
  Result:=VarArrayCreate([0,L-1],varByte);
  P:=VarArrayLock(Result);
  try
    Move(Buffer^,P^,L);
  finally
    VarArrayUnLock(Result);
  end;
  FreeMem(Buffer,L);
 end;


klient :
procedure TKonfUctJed.SetImage;
var
  P: Pointer;
  L: integer;
  TempStream:TMemoryStream;
  V:OleVariant;
begin
    V:=ComServer.Logo;
    L:=VarArrayHighBound(V,1)-VarArrayLowBound(V,1)+1;
    GetMem(Buffer,L);
    P:=VarArrayLock(V);
    try
      Move(P^,Buffer^,L);
    finally
      VarArrayUnLock(V);
    end;

    TempStream:=TMemoryStream.Create;
    try
      TempStream.WriteBuffer(Buffer^,L);
      Image1.Picture.Bitmap.LoadFromStream(TempStream);file://obrazek
    finally
      TempStream.Free;
    end;
    FreeMem(Buffer,L);
 end;


S pozdravem
ing. Richard Kejval
IC Software s.r.o
Mobil: +420602477679


Odpovedá: Richard Kejval

12. 11. 2002 10:55

No nevim, co ta delka toho streamu je v poradku ? Zkusil bych to mozna
prvne ulozit na disk pres filestream, prohlidnout a pak teprve nacist,
protoze nacist buffer ze streamu, kdyz znam jeho velikost, by nemel byt
problem a tuto konstrukci bezne pouzivam.

S pozdravem
ing. Richard Kejval
IC Software s.r.o
Mobil: +420602477679


> Ahoj,
> bohuzel to takhle nechodi. Padne to na radku
>
> TempStream.ReadBuffer(Buffer^,L); file://Zde se vyhlasi chyba cteni
proudu.
>
> Jestli te jeste neco napada, tak budu vdecny za kazdou radu.
>
> Libor
>
> -----Original Message-----
> From: delphi-l-owner@clexpert.cz [mailto:delphi-l-owner@clexpert.cz]On
> Behalf Of Richard Kejval
> Sent: Tuesday, November 12, 2002 9:04 AM
> To: delphi-l@clexpert.cz
> Subject: Re: Predavani obrazku (TBitmap) pres COM/DCOM
>
>
>
> Ahoj,
> melo by to byt asi takhle, ale pisu to z hlavy, tak tam muze
> byt chyba, asi by to slo i bez toho tempstreamu, ale nechal
> jsem ho tam.
>
> server:
> function TCOMServer.Get_Logo: OleVariant;
> var
> TempStream:TMemoryStream;
> P:Pointer; L:Integer;
> Buffer:PChar;
> begin
> TempStream:=TMemoryStream.Create;
> try
> Logo.SaveToStream(TempStream); file://Logo: TBitmap
> L:=TempStream.Size;
> GetMem(Buffer,L);
> TempStream.ReadBuffer(Buffer^,L);
> finally
> TempStream.Free;
> end;
> Result:=VarArrayCreate([0,L-1],varByte);
> P:=VarArrayLock(Result);
> try
> Move(Buffer^,P^,L);
> finally
> VarArrayUnLock(Result);
> end;
> FreeMem(Buffer,L);
> end;
>
>
> klient :
> procedure TKonfUctJed.SetImage;
> var
> P: Pointer;
> L: integer;
> TempStream:TMemoryStream;
> V:OleVariant;
> begin
> V:=ComServer.Logo;
> L:=VarArrayHighBound(V,1)-VarArrayLowBound(V,1)+1;
> GetMem(Buffer,L);
> P:=VarArrayLock(V);
> try
> Move(P^,Buffer^,L);
> finally
> VarArrayUnLock(V);
> end;
>
> TempStream:=TMemoryStream.Create;
> try
> TempStream.WriteBuffer(Buffer^,L);
> Image1.Picture.Bitmap.LoadFromStream(TempStream);file://obrazek
> finally
> TempStream.Free;
> end;
> FreeMem(Buffer,L);
> end;
>
>
> S pozdravem
> ing. Richard Kejval
> IC Software s.r.o
> Mobil: +420602477679
>
>
>
>
>